home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Mac OS USB DDK_v1.0.1 / Examples / PrinterClassDriver / SafeNameRegistry.cp < prev    next >
Encoding:
Text File  |  1998-09-03  |  21.0 KB  |  663 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SafeNameRegistry.cp
  3.  
  4.     Contains:    Stub routines for name registry calls
  5.  
  6.     Think of the Name Registry as a database used by System software 
  7.     to keep track of hardware and other settings. Its up to the 
  8.     indivdual software (called expert software) to insert and remove 
  9.     entries from the Name Registry. The information contained inside 
  10.     the entries can be whatever the expert software deems important.
  11.  
  12.     The Name Registry is only available on PCI based Macs. The Name
  13.     Registry routines reside in a PPC shared library (there isn't a
  14.     68K version), hence the need for these stub routines. When we build
  15.     fat drivers there is a chance on a PPC of running the 68K version
  16.     of the driver. Therefore we needed a way of calling into the Name
  17.     Registry shared library from 68K code. These routines will load the
  18.     Name Registry library and create procptrs for the needed calls. The
  19.     same stub calls will work on PPC and 68K
  20.  
  21. */
  22.  
  23. #ifndef __Chooser__
  24. #include "Chooser.h"
  25. #endif
  26.  
  27. #ifndef __CODEFRAGMENTS__
  28. #include <CodeFragments.h>
  29. #endif
  30.  
  31. #ifndef __MIXEDMODE__
  32. #include <MixedMode.h>
  33. #endif
  34.  
  35. #ifndef __GESTALT__
  36. #include <Gestalt.h>
  37. #endif
  38.  
  39. #ifndef __ERRORS__
  40. #include <Errors.h>
  41. #endif
  42.  
  43. #ifndef __DIALOGS__
  44. #include <Dialogs.h>
  45. #endif
  46.  
  47. #ifndef __SafeNameRegistry__
  48. #include "SafeNameRegistry.h"
  49. #endif
  50.  
  51. /******************************************************************************
  52.     Prototypes
  53.  ******************************************************************************/
  54.  
  55. // prototypes used to find address of routine in name registry library
  56. OSErr FindAddress(Ptr* pSymAddr, Str255 pSymName, ProcInfoType pProcInfo);
  57. pascal OSErr GetSystemArchitecture(OSType *archType);
  58.  
  59. /******************************************************************************
  60.     Typedefs
  61.  ******************************************************************************/
  62.  
  63. // proc typedefs for calling routines in the name registry library
  64. typedef pascal OSStatus (*RegistryEntryIDInitProcPtr) ( RegEntryID* id );
  65. typedef pascal OSStatus (*RegistryCStrEntryLookupProcPtr) ( RegEntryID* searchPointID, 
  66.             RegCStrPathName* pathName, RegEntryID*foundEntry );
  67. typedef pascal OSStatus (*RegistryEntryIterateCreateProcPtr) ( RegEntryIter* cookie );
  68. typedef pascal OSStatus (*RegistryEntryIterateDisposeProcPtr) ( RegEntryIter* cookie );
  69. typedef pascal OSStatus (*RegistryEntryIterateSetProcPtr) ( RegEntryIter* cookie, RegEntryID *startEntryID );
  70. typedef pascal OSStatus (*RegistryEntryIterateProcPtr) ( RegEntryIter *cookie, 
  71.             RegEntryIterationOp relationship, RegEntryID *foundEntry, Boolean *done );
  72. typedef pascal OSStatus (*RegistryEntryIDDisposeProcPtr) ( RegEntryID* id );
  73. typedef pascal OSStatus (*RegistryPropertyGetProcPtr) ( RegEntryID *entryID, 
  74.             RegPropertyName *propertyName, void *propertyValue, RegPropertyValueSize *propertySize );
  75.  
  76. /******************************************************************************
  77.     Constants
  78.  ******************************************************************************/
  79.  
  80. #define    kNoNameRegistryAlert        3000
  81.  
  82. // stack descriptors used in the name registry stub calls to pass params
  83. // to the proper routine in the name registry shared library
  84.  
  85. enum {
  86.     kRegistryEntryIDInitProcInfo = kPascalStackBased
  87.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  88.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryID*)))
  89. };
  90. enum {
  91.     kRegistryCStrEntryLookupProcInfo = kPascalStackBased
  92.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  93.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryID*)))
  94.     | STACK_ROUTINE_PARAMETER( 2, SIZE_CODE(sizeof( RegCStrPathName*)))
  95.     | STACK_ROUTINE_PARAMETER( 3, SIZE_CODE(sizeof( RegEntryID*)))
  96. };
  97. enum {
  98.     kRegistryEntryIterateCreateProcInfo = kPascalStackBased
  99.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  100.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryIter*)))
  101. };
  102. enum {
  103.     kRegistryEntryIterateDisposeProcInfo = kPascalStackBased
  104.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  105.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryIter*)))
  106. };
  107. enum {
  108.     kRegistryEntryIterateSetProcInfo = kPascalStackBased
  109.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  110.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryIter*)))
  111.     | STACK_ROUTINE_PARAMETER( 2, SIZE_CODE(sizeof( RegEntryID*)))
  112. };
  113. enum {
  114.     kRegistryEntryIterateProcInfo = kPascalStackBased
  115.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  116.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryIter*)))
  117.     | STACK_ROUTINE_PARAMETER( 2, SIZE_CODE(sizeof( RegEntryIterationOp)))
  118.     | STACK_ROUTINE_PARAMETER( 3, SIZE_CODE(sizeof( RegEntryID*)))
  119.     | STACK_ROUTINE_PARAMETER( 4, SIZE_CODE(sizeof( Boolean*)))
  120. };
  121. enum {
  122.     kRegistryEntryIDDisposeProcInfo = kPascalStackBased
  123.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  124.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryID*)))
  125. };
  126. enum {
  127.     kRegistryPropertyGetProcInfo = kPascalStackBased
  128.     | RESULT_SIZE( SIZE_CODE(sizeof(OSStatus)))
  129.     | STACK_ROUTINE_PARAMETER( 1, SIZE_CODE(sizeof( RegEntryID*)))
  130.     | STACK_ROUTINE_PARAMETER( 2, SIZE_CODE(sizeof( RegPropertyName*)))
  131.     | STACK_ROUTINE_PARAMETER( 3, SIZE_CODE(sizeof( void*)))
  132.     | STACK_ROUTINE_PARAMETER( 4, SIZE_CODE(sizeof( RegPropertyValueSize*)))
  133. };
  134.  
  135. /*-----------------------------------------------------------------------------*
  136.  
  137.     NameRegistryInstalled
  138.     
  139.     Desc:        Test to see if the name registry exists on this machine
  140.  
  141.     In:            None
  142.  
  143.     Out:        True if name registry exists else false
  144.     
  145.     History:
  146.  
  147.     18 Mar 98    gp        Added.
  148.     
  149. *-----------------------------------------------------------------------------*/
  150. Boolean    NameRegistryInstalled( void )
  151. {
  152.     OSErr    err=noErr;        // result from gestalt call
  153.     long    result;
  154.     USBGlobalsHandle    gGlobals=nil;        // our global data area
  155.  
  156.     gGlobals = GetGlobalStorage();
  157.  
  158.     // if not our first time then return previous result
  159.     if( (**gGlobals).checkedForNameRegistry == true )
  160.         return (**gGlobals).hasNameRegistry;
  161.     else {
  162.  
  163.     // check to see if name registry exists
  164.         err = Gestalt(gestaltNameRegistryVersion, &result);
  165.         if( err == noErr )
  166.             (**gGlobals).hasNameRegistry = true;
  167.         else {
  168.             (**gGlobals).hasNameRegistry = false;
  169.     // put up alert if it isn't installed
  170.             StopAlert(kNoNameRegistryAlert, nil);
  171.         }
  172.         (**gGlobals).checkedForNameRegistry=true;
  173.     }
  174.     return (**gGlobals).hasNameRegistry;
  175. }
  176.  
  177. /*-----------------------------------------------------------------------------*
  178.  
  179.     SafeRegistryEntryIDInit
  180.     
  181.     Desc:        Stub code for name registry routine 'RegistryEntryIDInit'
  182.  
  183.     In:            id - pointer to a RegEntryID to initialize
  184.  
  185.     Out:        returns any errors which may have occur
  186.     
  187.     History:
  188.  
  189.     18 Mar 98    gp        Added.
  190.     
  191. *-----------------------------------------------------------------------------*/
  192.  
  193. OSStatus SafeRegistryEntryIDInit(RegEntryID *id)
  194. {
  195.     OSStatus    anErr=-1;                // return value
  196.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  197.  
  198.     gGlobals = GetGlobalStorage();
  199.  
  200.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryEntryIDInitAddr != (Ptr) nil )
  201.         anErr = ((RegistryEntryIDInitProcPtr) (**gGlobals).RegistryEntryIDInitAddr) (id);
  202.     return anErr;
  203. }
  204.  
  205. /*-----------------------------------------------------------------------------*
  206.  
  207.     SafeRegistryCStrEntryLookup
  208.     
  209.     Desc:        Stub code for name registry routine 'RegistryCStrEntryLookup'
  210.  
  211.     In:            searchPointID - the RegEntryID to start searching from
  212.                 pathName - the cstring path of the entry to find
  213.                 foundEntry - where to store the found entry
  214.  
  215.     Out:        foundEntry - the RegEntryID of any found entry
  216.                 returns any errors which may have occur
  217.     
  218.     History:
  219.  
  220.     18 Mar 98    gp        Added.
  221.     
  222. *-----------------------------------------------------------------------------*/
  223. OSStatus SafeRegistryCStrEntryLookup( RegEntryID *searchPointID, RegCStrPathName *pathName, RegEntryID *foundEntry)
  224. {
  225.     OSStatus    anErr=-1;                // return value
  226.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  227.  
  228.     gGlobals = GetGlobalStorage();
  229.     
  230.     // now call it
  231.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryCStrEntryLookupAddr != (Ptr) nil )
  232.         anErr = ((RegistryCStrEntryLookupProcPtr) (**gGlobals).RegistryCStrEntryLookupAddr) (searchPointID, pathName, foundEntry);
  233.     return anErr;
  234. }
  235.  
  236. /*-----------------------------------------------------------------------------*
  237.  
  238.     SafeRegistryEntryIterateCreate
  239.     
  240.     Desc:        Stub code for name registry routine 'RegistryEntryIterateCreate'
  241.  
  242.     In:            id - pointer to a RegEntryIter to initialize
  243.  
  244.     Out:        returns any errors which may have occur
  245.     
  246.     History:
  247.  
  248.     18 Mar 98    gp        Added.
  249.     
  250. *-----------------------------------------------------------------------------*/
  251. OSStatus SafeRegistryEntryIterateCreate(RegEntryIter *cookie)
  252. {
  253.     OSStatus    anErr=-1;                // return value
  254.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  255.  
  256.     gGlobals = GetGlobalStorage();
  257.  
  258.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryEntryIterateCreateAddr != (Ptr) nil )
  259.         anErr = ((RegistryEntryIterateCreateProcPtr) (**gGlobals).RegistryEntryIterateCreateAddr) (cookie);
  260.     return anErr;
  261. }
  262.  
  263. /*-----------------------------------------------------------------------------*
  264.  
  265.     SafeRegistryEntryIterateDispose
  266.     
  267.     Desc:        Stub code for name registry routine 'RegistryEntryIterateDispose'
  268.  
  269.     In:            cookie - iterator to dispose
  270.  
  271.     Out:        returns any errors which may have occur
  272.     
  273.     History:
  274.  
  275.     18 Mar 98    gp        Added.
  276.     
  277. *-----------------------------------------------------------------------------*/
  278. OSStatus SafeRegistryEntryIterateDispose(RegEntryIter *cookie)
  279. {
  280.     OSStatus    anErr=-1;                // return value
  281.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  282.  
  283.     gGlobals = GetGlobalStorage();
  284.  
  285.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryEntryIterateDisposeAddr != (Ptr) nil )
  286.         anErr = ((RegistryEntryIterateDisposeProcPtr) (**gGlobals).RegistryEntryIterateDisposeAddr) (cookie);
  287.     return anErr;
  288. }
  289.  
  290. /*-----------------------------------------------------------------------------*
  291.  
  292.     SafeRegistryEntryIterateSet
  293.     
  294.     Desc:        Stub code for name registry routine 'RegistryEntryIterateSet'
  295.  
  296.     In:            cookie - pointer to iterator to set
  297.                 startEntryID - name registry entry to start iterating from
  298.  
  299.     Out:        returns any errors which may have occur
  300.     
  301.     History:
  302.  
  303.     18 Mar 98    gp        Added.
  304.     
  305. *-----------------------------------------------------------------------------*/
  306. OSStatus SafeRegistryEntryIterateSet(RegEntryIter *cookie, RegEntryID *startEntryID)
  307. {
  308.     OSStatus    anErr=-1;                // return value
  309.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  310.  
  311.     gGlobals = GetGlobalStorage();
  312.  
  313.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryEntryIterateSetAddr != (Ptr) nil )
  314.         anErr = ((RegistryEntryIterateSetProcPtr) (**gGlobals).RegistryEntryIterateSetAddr) (cookie, startEntryID);
  315.     return anErr;
  316. }
  317.  
  318. /*-----------------------------------------------------------------------------*
  319.  
  320.     SafeRegistryEntryIterate
  321.     
  322.     Desc:        Stub code for name registry routine 'RegistryEntryIterate'
  323.  
  324.     In:            cookie - iterator to use
  325.                 relationship - direction to iterate
  326.                 foundEntry - where to store next name entry found
  327.                 done - tells if we're done with iteration
  328.  
  329.     Out:        foundEntry - RegEntryID of name entry found
  330.                 done - true if no more entries found
  331.                 returns any errors which may have occur
  332.     
  333.     History:
  334.  
  335.     18 Mar 98    gp        Added.
  336.     
  337. *-----------------------------------------------------------------------------*/
  338. OSStatus SafeRegistryEntryIterate(RegEntryIter *cookie, RegEntryIterationOp relationship, 
  339.         RegEntryID *foundEntry, Boolean *done)
  340. {
  341.     OSStatus    anErr=-1;                // return value
  342.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  343.  
  344.     gGlobals = GetGlobalStorage();
  345.  
  346.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryEntryIterateAddr != (Ptr) nil )
  347.         anErr = ((RegistryEntryIterateProcPtr) (**gGlobals).RegistryEntryIterateAddr) (cookie, relationship, foundEntry, done);
  348.     return anErr;
  349. }
  350.  
  351. /*-----------------------------------------------------------------------------*
  352.  
  353.     SafeRegistryEntryIDDispose
  354.     
  355.     Desc:        Stub code for name registry routine 'RegistryEntryIDDispose'
  356.  
  357.     In:            id - RegEntryID to dispose
  358.  
  359.     Out:        returns any errors which may have occur
  360.     
  361.     History:
  362.  
  363.     18 Mar 98    gp        Added.
  364.     
  365. *-----------------------------------------------------------------------------*/
  366. OSStatus SafeRegistryEntryIDDispose(RegEntryID *id)
  367. {
  368.     OSStatus    anErr=-1;                // return value
  369.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  370.  
  371.     gGlobals = GetGlobalStorage();
  372.  
  373.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryEntryIDDisposeAddr != (Ptr) nil )
  374.         anErr = ((RegistryEntryIDDisposeProcPtr) (**gGlobals).RegistryEntryIDDisposeAddr) (id);
  375.     return anErr;
  376. }
  377.  
  378. /*-----------------------------------------------------------------------------*
  379.  
  380.     SafeRegistryPropertyGet
  381.     
  382.     Desc:        Stub code for name registry routine 'RegistryPropertyGet'
  383.  
  384.     In:            entryID - RegEntryID value that identifies a name entry
  385.                 propertyName - name of the property
  386.                 propertyValue - buffer to hold the property
  387.                 propertySize - size of the property buffer
  388.  
  389.     Out:        propertySize - size of the property retrieved
  390.                 returns any errors which may have occur
  391.     
  392.     History:
  393.  
  394.     18 Mar 98    gp        Added.
  395.     
  396. *-----------------------------------------------------------------------------*/
  397. OSStatus SafeRegistryPropertyGet( RegEntryID *entryID, RegPropertyName *propertyName, 
  398.         void *propertyValue, RegPropertyValueSize *propertySize)
  399. {
  400.     OSStatus    anErr=-1;                // return value
  401.     USBGlobalsHandle    gGlobals=nil;    // our global data area
  402.  
  403.     gGlobals = GetGlobalStorage();
  404.  
  405.     if( gGlobals != nil && (Ptr) (**gGlobals).RegistryPropertyGetAddr != (Ptr) nil )
  406.         anErr = ((RegistryPropertyGetProcPtr) (**gGlobals).RegistryPropertyGetAddr) (entryID, propertyName, propertyValue, propertySize);
  407.     return anErr;
  408. }
  409.  
  410. /*-----------------------------------------------------------------------------*
  411.  
  412.     GetSystemArchitecture
  413.     
  414.     Desc:        Taken from 
  415.                 DTS Technote 1077 "Calling CFM Code from Classic 68K Code".
  416.                 Returns architect of current cpu during runtime.
  417.  
  418.  
  419.     In:            archType - address of variable to hold architect type
  420.  
  421.     Out:        archType - returns architect of current cpu pointed by this variable
  422.                 Also returns any errors
  423.     
  424.     History:
  425.  
  426.     18 Mar 98    gp        Added.
  427.     
  428. *-----------------------------------------------------------------------------*/
  429.  
  430. pascal OSErr GetSystemArchitecture(OSType *archType)
  431. {
  432.     long sSysArchitecture = 0; // static so we only Gestalt once.
  433.     OSErr tOSErr = noErr;
  434.     
  435.     *archType = kAnyCFragArch;   // assume wild architecture
  436.     
  437.     // If we don't know the system architecture yet...
  438.     if (sSysArchitecture == 0)
  439.         // ...Ask Gestalt what kind of machine we are running on.
  440.         tOSErr = Gestalt(gestaltSysArchitecture, &sSysArchitecture);
  441.     
  442.     if (tOSErr == noErr) // if no errors
  443.     {
  444.         if (sSysArchitecture == gestalt68k)   // 68k?
  445.              *archType = kMotorola68KCFragArch;   
  446.         else if (sSysArchitecture == gestaltPowerPC) // PPC?
  447.              *archType = kPowerPCCFragArch;       
  448.         else
  449.              tOSErr = gestaltUnknownErr;  // who knows what might be next?
  450.     }
  451.     return tOSErr;
  452. }
  453.  
  454. /*-----------------------------------------------------------------------------*
  455.  
  456.     FindAddress
  457.     
  458.     Desc:        Taken from 
  459.                 DTS Technote 1077 "Calling CFM Code from Classic 68K Code".
  460.                 Returns the address of a routine in a shared library
  461.  
  462.     In:            pSymAddr - address of variable to hold returned address
  463.                 pSymName - a pstring of the name of the routine
  464.                 pProcInfo - stack descriptor for the routine
  465.  
  466.     Out:        pSymAddr - the address of the routine pointed by this variable
  467.                 Also returns any errors
  468.     
  469.     History:
  470.  
  471.     10 Jun 98    gp        Init the address ptr passed in before using it
  472.     9  Jun 98    gp        Use our connection id to the name registry instead of
  473.                         opening it every time
  474.     18 Mar 98    gp        Added.
  475.     
  476. *-----------------------------------------------------------------------------*/
  477.  
  478. OSErr FindAddress(Ptr* pSymAddr, Str255 pSymName, ProcInfoType pProcInfo)
  479. {
  480.     CFragConnectionID sCID = 0;
  481.     OSType sArchType = kAnyCFragArch;
  482.     OSErr sOSErr = noErr;
  483.     USBGlobalsHandle    gGlobals=nil;        // our global data area
  484.  
  485.     Str255 errMessage;
  486.     Ptr mainAddr;
  487.     CFragSymbolClass symClass;
  488.           ISAType tISAType;
  489.     
  490.     *pSymAddr = (Ptr) kUnresolvedCFragSymbolAddress;
  491.  
  492.     if( NameRegistryInstalled() == false )
  493.         return -1;            // return general error - gp
  494.     
  495.     gGlobals = GetGlobalStorage();
  496.  
  497.     if (sArchType == kAnyCFragArch)  // if architecture is undefined...
  498.     {
  499.         sCID = 0;     // ...force (re)connect to library
  500.         sOSErr = GetSystemArchitecture(&sArchType); // determine architecture
  501.         if (sOSErr != noErr)
  502.              return sOSErr; // OOPS!
  503.     }
  504.     
  505.     if (sArchType == kMotorola68KCFragArch) // ...for CFM68K
  506.           tISAType = kM68kISA | kCFM68kRTA;
  507.     else if (sArchType == kPowerPCCFragArch)  // ...for PPC CFM
  508.           tISAType = kPowerPCISA | kPowerPCRTA;
  509.     else
  510.         sOSErr = gestaltUnknownErr; // who knows what might be next?
  511.     
  512.      sCID = (**gGlobals).sCID;
  513.     if (sCID == 0) // If we haven't connected to the library yet...
  514.     {
  515.         // NOTE: The library name is hard coded here.
  516.         // I try to isolate the glue code, one file per library.
  517.         // I have had developers pass in the Library name to allow
  518.         // plug-in type support. Additional code has to be added to
  519.         // each entry points glue routine to support multiple or
  520.         // switching connection IDs.
  521.         sOSErr = GetSharedLibrary("\pNameRegistryLib", sArchType, kLoadCFrag,
  522.                    &sCID, &mainAddr, errMessage);
  523.         if (sOSErr != noErr)
  524.              return sOSErr; // OOPS!
  525.          (**gGlobals).sCID = sCID;            // save connection id
  526.     }
  527.     
  528.     // If we haven't looked up this symbol yet...
  529.     if ((Ptr) *pSymAddr == (Ptr) kUnresolvedCFragSymbolAddress)    
  530.     {
  531.         // ...look it up now
  532.         sOSErr = FindSymbol(sCID,pSymName,pSymAddr,&symClass);
  533.         if (sOSErr != noErr) {// in case of error...
  534.          // ...clear the procedure pointer
  535.              *pSymAddr = (Ptr) kUnresolvedCFragSymbolAddress;
  536.         }
  537.         #if !GENERATINGCFM // if this is classic 68k code...
  538.          *pSymAddr = (Ptr)NewRoutineDescriptorTrap((ProcPtr) *pSymAddr,
  539.                       pProcInfo, tISAType);  // ...create a routine descriptor...
  540.         #endif
  541.     }
  542.     return sOSErr;
  543. }
  544.  
  545. /*-----------------------------------------------------------------------------*
  546.  
  547.     InitNameRegistryPtrs
  548.     
  549.     Desc:        Create all the proc ptrs to Name Registry calls we will
  550.                 need
  551.  
  552.     In:            None
  553.  
  554.     Out:        None
  555.     
  556.     History:
  557.  
  558.     10 Jun 98    gp        Use a local variable to store the routine address
  559.     9  Jun 98    gp        Init our connection id to the name registry
  560.     25 Mar 98    gp        Created
  561.     
  562. *-----------------------------------------------------------------------------*/
  563. void    InitNameRegistryPtrs( void )
  564. {
  565.     USBGlobalsHandle    gGlobals = nil;        // our global data area
  566.     Ptr                    address = nil;
  567.  
  568.     gGlobals = GetGlobalStorage();
  569.  
  570.     if( gGlobals != nil && NameRegistryInstalled() == true) {
  571.         (**gGlobals).sCID = 0;
  572.  
  573.         FindAddress( (Ptr*) &address, 
  574.                 "\pRegistryEntryIDInit", kRegistryEntryIDInitProcInfo );
  575.         (**gGlobals).RegistryEntryIDInitAddr = (ProcPtr) address;
  576.  
  577.         FindAddress( (Ptr*) &address, 
  578.                 "\pRegistryCStrEntryLookup", kRegistryCStrEntryLookupProcInfo );
  579.         (**gGlobals).RegistryCStrEntryLookupAddr = (ProcPtr) address;
  580.  
  581.         FindAddress( (Ptr*) &address, 
  582.                 "\pRegistryEntryIterateCreate", kRegistryEntryIterateCreateProcInfo );
  583.         (**gGlobals).RegistryEntryIterateCreateAddr = (ProcPtr) address;
  584.  
  585.         FindAddress( (Ptr*) &address, 
  586.                 "\pRegistryEntryIterateDispose", kRegistryEntryIterateDisposeProcInfo );
  587.         (**gGlobals).RegistryEntryIterateDisposeAddr = (ProcPtr) address;
  588.  
  589.         FindAddress( (Ptr*) &address, 
  590.                 "\pRegistryEntryIterateSet", kRegistryEntryIterateSetProcInfo );
  591.         (**gGlobals).RegistryEntryIterateSetAddr = (ProcPtr) address;
  592.  
  593.         FindAddress( (Ptr*) &address, 
  594.                 "\pRegistryEntryIterate", kRegistryEntryIterateProcInfo );
  595.         (**gGlobals).RegistryEntryIterateAddr = (ProcPtr) address;
  596.  
  597.         FindAddress( (Ptr*) &address, 
  598.                 "\pRegistryEntryIDDispose", kRegistryEntryIDDisposeProcInfo );
  599.         (**gGlobals).RegistryEntryIDDisposeAddr = (ProcPtr) address;
  600.  
  601.         FindAddress( (Ptr*) &address, 
  602.                 "\pRegistryPropertyGet", kRegistryPropertyGetProcInfo );
  603.         (**gGlobals).RegistryPropertyGetAddr = (ProcPtr) address;
  604.     }
  605. }
  606.  
  607. /*-----------------------------------------------------------------------------*
  608.  
  609.     RemoveNameRegistryPtrs
  610.     
  611.     Desc:        Remove all the proc ptrs we created for Name Registry calls
  612.  
  613.     In:            None
  614.  
  615.     Out:        None
  616.     
  617.     History:
  618.  
  619.     9  Jun 98    gp        Close our connection id to the name registry
  620.                         Use DisposeRoutineDescriptorTrap when disposing of the
  621.                         name registry routine descriptors
  622.     25 Mar 98    gp        Created
  623.     
  624. *-----------------------------------------------------------------------------*/
  625. void    RemoveNameRegistryPtrs(void)
  626. {
  627.     USBGlobalsHandle    gGlobals=nil;        // our global data area
  628.     CFragConnectionID sCID;
  629.  
  630.     
  631.     gGlobals = GetGlobalStorage();
  632.     if( gGlobals != nil ) {
  633.         // dispose of proc ptrs
  634.         
  635.         if( (**gGlobals).RegistryEntryIDInitAddr != nil )
  636.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryEntryIDInitAddr);
  637.         
  638.         if( (**gGlobals).RegistryCStrEntryLookupAddr != nil )
  639.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryCStrEntryLookupAddr);
  640.         
  641.         if( (**gGlobals).RegistryEntryIterateCreateAddr != nil )
  642.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryEntryIterateCreateAddr);
  643.         
  644.         if( (**gGlobals).RegistryEntryIterateDisposeAddr != nil )
  645.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryEntryIterateDisposeAddr);
  646.         
  647.         if( (**gGlobals).RegistryEntryIterateSetAddr != nil )
  648.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryEntryIterateSetAddr);
  649.         
  650.         if( (**gGlobals).RegistryEntryIterateAddr != nil )
  651.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryEntryIterateAddr);
  652.         
  653.         if( (**gGlobals).RegistryEntryIDDisposeAddr != nil )
  654.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryEntryIDDisposeAddr);
  655.         
  656.         if( (**gGlobals).RegistryPropertyGetAddr != nil )
  657.             DisposeRoutineDescriptorTrap( (**gGlobals).RegistryPropertyGetAddr);
  658.  
  659.         sCID = (**gGlobals).sCID;
  660.         CloseConnection( &sCID );
  661.     }
  662. }
  663.